using ExampleWebApplication.Entities;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace ExampleWebApplication.Infraestruture.NHibernate.EntityMappings
{
    public class ProductMap : ClassMapping<Product>
    {
        public ProductMap()
        {
            Table("Products");
            Id(x => x.ProductID, map => { map.Generator(Generators.Identity); map.Column("ProductID"); });
            Property(x => x.ProductName, map => { map.Column("ProductName"); map.NotNullable(true); map.Length(40); });
            Property(x => x.QuantityPerUnit, map => { map.Column("QuantityPerUnit"); map.Length(20); });
            Property(x => x.UnitPrice, map => map.Column("UnitPrice"));
            Property(x => x.UnitsInStock, map => map.Column("UnitsInStock"));
            Property(x => x.Units_On_Order, map => map.Column("UnitsOnOrder"));
            Property(x => x.ReorderLevel, map => map.Column("ReorderLevel"));
            Property(x => x.Discontinued, map => { map.Column("Discontinued"); map.NotNullable(true); });
            ManyToOne(x => x.Supplier, map => map.Column("SupplierID"));
            ManyToOne(x => x.Category, map => map.Column("CategoryID"));
            Bag(x => x.OrderDetails, map => { map.Inverse(true); map.Key(key => key.Column("ProductID")); }, rel => rel.OneToMany());
        }
    }
}
